﻿using Autodesk.AutoCAD.DatabaseServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _12注释样式
{
    public static partial class DimStyleTool
    {
        /// <summary>
        /// 新建注释样式
        /// </summary>
        /// <param name="db">图形数据库</param>
        /// <param name="dimStyleName">注释样式名</param>
        public static ObjectId AddDimStyle(this Database db, string dimStyleName)
        {
            ObjectId dimStyleId = ObjectId.Null;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //打开注释样式表
                DimStyleTable dst = (DimStyleTable)trans.GetObject(db.DimStyleTableId, OpenMode.ForRead);
                if (!dst.Has(dimStyleName))
                {
                    DimStyleTableRecord dstr = new DimStyleTableRecord();
                    dstr.Name = dimStyleName;
                    dst.UpgradeOpen();
                    dimStyleId = dst.Add(dstr);
                    trans.AddNewlyCreatedDBObject(dstr, true);
                    trans.Commit();
                }
                else
                {
                    dimStyleId = dst[dimStyleName];
                }
            }
            return dimStyleId;
        }

     
    }
}
